package name.zxw.rabbitmq.workqueues;

import com.rabbitmq.client.CancelCallback;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;
import name.zxw.rabbitmq.util.RabbitMqUtils;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @author ZhangXinWang
 * @date 2022/5/18 20:10
 */
public class Worker01 {

    public static final String QUEUE_NAME = "hello";

    public static void main(String[] args) {
        try {
            Channel channel = RabbitMqUtils.getChannel();

            DeliverCallback deliverCallback = (consumerTag, message) -> {
                System.out.println("consumerTag = " + consumerTag);
                System.out.println("接收到的消息:" + new String(message.getBody()));
            };
            CancelCallback cancelCallback = (consumerTag) -> {
                System.out.println("consumerTag = " + consumerTag);
                System.out.println("消费者取消消费回调逻辑");
            };

            System.out.println("C2等待接收消息...");
            channel.basicConsume(QUEUE_NAME, true, deliverCallback, cancelCallback);

            channel.basicAck(123,true);
            channel.basicNack(123,false,true);
            channel.basicReject(123,true);

        } catch (IOException e) {
            throw new RuntimeException(e);
        } catch (TimeoutException e) {
            throw new RuntimeException(e);
        }
    }


}
